package hw.q1;

import java.util.*;

public class FiberOpticInstallation {

    private static final int[][] DIRECTIONS = {
        {0, 1},
        {1, 0},
        {0, -1},
        {-1, 0}
    };

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int a1 = scanner.nextInt();
        int a2 = scanner.nextInt();
        int b1 = scanner.nextInt();
        int b2 = scanner.nextInt();
        int k = scanner.nextInt();
        
        boolean[][] grid = new boolean[n][m];
        for (int i = 0; i < k; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            grid[y][x] = true;
        }
        
        int result = shortestPath(grid, a1, a2, b1, b2, m, n);
        System.out.println(result);
    }
    
    private static int shortestPath(boolean[][] grid, int startX, int startY, int endX, int endY, int m, int n) {
        if (grid[startY][startX] || grid[endY][endX]) {
            return -1;
        }

        Queue<int[]> queue = new LinkedList<>();
        boolean[][] visited = new boolean[n][m];
        queue.offer(new int[]{startX, startY, 0});
        visited[startY][startX] = true;

        while (!queue.isEmpty()) {
            int[] current = queue.poll();
            int x = current[0];
            int y = current[1];
            int distance = current[2];

            if (x == endX && y == endY) {
                return distance;
            }

            for (int[] direction : DIRECTIONS) {
                int newX = x + direction[0];
                int newY = y + direction[1];

                if (newX >= 0 && newX < m && newY >= 0 && newY < n && !grid[newY][newX] && !visited[newY][newX]) {
                    queue.offer(new int[]{newX, newY, distance + 1});
                    visited[newY][newX] = true;
                }
            }
        }

        return -1;
    }
}
